<?php
namespace app\admin\controller;
use think\Db;
class Orderint extends Common
{

    //用户积分下注列表
    public function index()
    {   
        if(request() -> isPost()){
            $key = input('post.key');
            $page = input('page')?input('page'):1;
            $pageSize =input('limit')?input('limit'):10;
            $list = DB::table('pre_common_credit_log')
                  ->alias('a')
                  ->join('pre_common_member b','a.uid = b.uid')
                  ->join('pre_common_usergroup c','a.relatedid = c.groupid')
                  ->field('b.username,c.grouptitle,a.*')
                  ->where('a.logid|b.username','like','%'.$key.'%')
                  ->where('a.operation','UGP')
                  ->order('uid desc')
                  ->paginate(array('list_rows'=>$pageSize,'page'=>$page))
                  ->toArray();
            if($list['data']){     
                foreach ($list['data'] as $key => $value) {
                    $list['data'][$key]['dateline'] = date('Y-m-d H:i:s',$value['dateline']);
                }  
            }             
            return json(['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1]);
        }
        return $this->fetch();
    }

    //删除单条记录(删除数据)
    public function del()
    {   
        $data['logid'] = input('param.logid');  
        if($data){
            $del = db('common_credit_log')->where($data)->delete();
            if($del){
                return json(['code'=>1,'msg'=>'删除成功']);
            }else{
                return json(['code'=>0,'msg'=>'删除失败']);
            }
        }
        
    }

    //批量删除(删除数据)
    public function delall()
    {   
        if(request() -> isPost()){
            $ids = $_POST['logids'];  
            $all = db('common_credit_log')->delete($ids);
            if($all){
                return json(['code'=>1,'msg'=>'删除成功']);
            }else{
                return json(['code'=>0,'msg'=>'删除失败']);
            }
        }
    }

}